package e

var message map[uint32]string

func init() {
	message = make(map[uint32]string)

	message[SUCCESS] = "请求成功"
	message[PermissionDenied] = "权限拒绝"
	message[ErrorNotFound] = "内容不存在"
	message[ErrorParam] = "参数错误"
	message[ErrTimeout] = "请求超时或认证错误请检查配置"
	message[ServerCommonError] = "服务器异常"
	message[DBError] = "数据库繁忙"
	message[RDBError] = "缓存异常"
	message[ClusterError] = "计算集群异常"
	message[ClusterLock] = "当前实验节点暂时无法提供实验资源"
	message[NotSupport] = "请求参数不支持"
	message[ErrorDelete] = "资源被引用，无法删除"
	message[ErrorExpire] = "资源已过期"
	message[ErrorFileUpload] = "文件上传失败"

	// Community module error messages
	// Menu errors
	message[MenuNameEmpty] = "专栏名称不能为空"
	message[MenuNameExists] = "专栏名称已存在"
	message[MenuNotFound] = "专栏不存在"
	message[MenuHasTopics] = "专栏下存在话题，不能删除"

	// Topic errors
	message[TopicNameEmpty] = "话题名称不能为空"
	message[TopicNotFound] = "话题不存在"
	message[TopicHasPosts] = "话题下存在帖子，不能删除"

	// Post errors
	message[PostTitleEmpty] = "帖子标题不能为空"
	message[PostContentEmpty] = "帖子内容不能为空"
	message[PostNotFound] = "帖子不存在"
	message[PostPermission] = "暂无权限在此话题下发帖"
	message[PostNotOwner] = "无权限操作此帖子"
	message[PostTagEmpty] = "标签不能为空"

	// Comment errors
	message[CommentContentEmpty] = "评论内容不能为空"
	message[CommentNotFound] = "评论不存在"
	message[CommentPostNotFound] = "帖子不存在"
	message[CommentNotOwner] = "无权限操作此评论"
}

func MapErrMsg(code uint32) string {
	if msg, ok := message[code]; ok {
		return msg
	} else {
		return message[ServerCommonError]
	}
}
